package com.kll.carolinehmibiz.presentation.presenter

import android.content.Context
import com.kll.carolinehmibiz.OperationManager
import com.kll.carolinehmibiz.model.OperateListener
import com.kll.carolinehmibiz.presentation.BasePresenter
import com.kll.carolinehmibiz.presentation.listener.RegisterProtocol

/**
 * ====================================================
 * Created by Ziliang Cai on 2021/12/7 17:23
 * <a href="mailto:752777456@qq.com">Contact me</a>
 * ====================================================
 */
class RegisterPresenter(context: Context, mView: RegisterProtocol.IView) : BasePresenter(context), RegisterProtocol.IPresenter {

    private var mView: RegisterProtocol.IView? = mView
    override fun getVerifyCode(mobile: String) {
        OperationManager.getInstancce().getVerifyCode(mobile, object: OperateListener {
            override fun onSuccess(state: Int, obj: Any?) {
                mView?.sendVerifyCodeSuccessed()
            }

            override fun onFail(code: Int, message: String) {
                mView?.sendVerifyCodeFailed("")
            }

        })
    }

    override fun register(sn: String, phone: String, code: String) {
       OperationManager.getInstancce().register(sn,phone, code, object: OperateListener {
           override fun onSuccess(state: Int, obj: Any?) {
               mView?.registerSuccessed()
           }

           override fun onFail(code: Int, message: String) {
               mView?.registerFailed("")
           }

       })
    }

    override fun onViewAdded() {
        super.onViewAdded()

        mView = null
    }


}